import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '@/layout'

Vue.use(Router)

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/500',
    component: () => import('@/views/500'),
    hidden: true
  },


  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    hidden: true,
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }]
  },

  {
    path: '/blog',
    component: Layout,
    redirect: '/blog/blogTag',
    name: '内容管理',
    meta: { title: '内容管理', icon: 'el-icon-s-fold' },
    children: [
      {
        path: 'blog',
        name: '文章管理',
        component: () => import('@/views/blog/blog'),
        meta: { title: '文章管理', icon: 'el-icon-document' }
      },
      {
        path: 'blogTag',
        name: '标签管理',
        component: () => import('@/views/blog/blogTag'),
        meta: { title: '标签管理', icon: 'el-icon-collection-tag' }
      },
      {
        path: 'blogSort',
        name: '分类管理',
        component: () => import('@/views/blog/blogSort'),
        meta: { title: '分类管理', icon: 'el-icon-menu' }
      },
      // {
      //   path: 'blogRecommend',
      //   name: '推荐管理',
      //   component: () => import('@/views/blog/blogRecommend'),
      //   meta: { title: '推荐管理', icon: 'el-icon-position' }
      // },
      // {
      //   path: 'collect',
      //   name: '收藏管理',
      //   component: () => import('@/views/blog/collect'),
      //   meta: { title: '收藏管理', icon: 'el-icon-collection' }
      // }
    ]
  },

  {
    path: '/authority',
    component: Layout,
    redirect: '/authority/admin',
    name: '权限管理',
    meta: { title: '权限管理', icon: 'el-icon-lock' },
    children: [
      {
        path: 'admin',
        name: '管理员管理',
        component: () => import('@/views/authority/admin'),
        meta: { title: '管理员管理', icon: 'el-icon-user' }
      },
      {
        path: 'role',
        name: '角色管理',
        component: () => import('@/views/authority/role'),
        meta: { title: '角色管理', icon: 'el-icon-key' }
      },
      // {
      //   path: 'categoryMenu',
      //   name: '菜单管理',
      //   component: () => import('@/views/authority/categoryMenu'),
      //   meta: { title: '菜单管理', icon: 'el-icon-s-operation' }
      // },
      // {
      //   path: 'button',
      //   name: '按钮管理',
      //   component: () => import('@/views/authority/button'),
      //   meta: { title: '按钮管理', icon: 'el-icon-thumb' }
      // }
    ]
  },
  // {
  //   path: '/picture',
  //   component: Layout,
  //   redirect: '/picture/pictureSort',
  //   name: '图片管理',
  //
  //   alwaysShow: true ,
  //   meta: { title: '图片管理', icon: 'el-icon-picture' },
  //   children: [
  //     {
  //       path: 'picture',
  //       name: '图片上传',
  //       component: () => import('@/views/picture/picture'),
  //       meta: { title: '图片管理', icon: 'el-icon-picture-outline' }
  //     },
  //     {
  //       path: 'pictureSort',
  //       name: '图片类别',
  //       component: () => import('@/views/picture/pictureSort'),
  //       meta: { title: '图片类别', icon: 'el-icon-folder' }
  //     },
  //   ]
  // },

  {
    path: '/system',
    component: Layout,
    redirect: '/system/webConfig',
    name: '系统管理',
    meta: { title: '系统管理', icon: 'el-icon-s-tools' },
    children: [
      // {
      //   path: 'aboutMe',
      //   name: '关于我',
      //   component: () => import('@/views/system/aboutMe'),
      //   meta: { title: '关于我', icon: 'el-icon-user-solid' }
      // },
      // {
      //   path: 'sysDictType',
      //   name: '字典管理',
      //   component: () => import('@/views/system/SysDictType'),
      //   meta: { title: '字典管理', icon: 'el-icon-notebook-2' }
      // },
      {
        path: 'webConfig',
        name: '网站配置',
        component: () => import('@/views/system/webConfig'),
        meta: { title: '网站配置', icon: 'el-icon-news' }
      },
      // {
      //   path: 'systemConfig',
      //   name: '系统配置',
      //   component: () => import('@/views/system/systemConfig'),
      //   meta: { title: '系统配置', icon: 'el-icon-setting' }
      // }
    ]
  },
  // {
  //   path: '/message',
  //   component: Layout,
  //   redirect: '/message/comment',
  //   name: '消息管理',
  //   meta: { title: '消息管理', icon: 'el-icon-s-comment' },
  //   children: [
  //     {
  //       path: 'comment',
  //       name: '评论管理',
  //       component: () => import('@/views/message/comment'),
  //       meta: { title: '评论管理', icon: 'el-icon-chat-dot-round' }
  //     },
  //     {
  //       path: 'feedback',
  //       name: '反馈管理',
  //       component: () => import('@/views/message/feedback'),
  //       meta: { title: '反馈管理', icon: 'el-icon-news' }
  //     }
  //   ]
  // },
  {
    path: '/restapi',
    component: Layout,
    redirect: '/restapi/adminRestApi',
    name: '接口管理',
    meta: { title: '接口管理', icon: 'el-icon-s-ticket' },
    children: [
      {
        path: 'adminRestApi',
        name: 'Admin接口',
        component: () => import('@/views/restapi/adminRestApi'),
        meta: { title: 'Admin接口', icon: 'el-icon-coordinate' }
      },
      {
        path: 'webRestApi',
        name: 'web接口',
        component: () => import('@/views/restapi/webRestApi'),
        meta: { title: 'Web接口', icon: 'el-icon-connection' }
      },
      {
        path: 'pictureRestApi',
        name: 'Picture接口',
        component: () => import('@/views/restapi/pictureRestApi'),
        meta: { title: 'Picture接口', icon: 'el-icon-picture-outline-round' }
      },
      {
        path: 'searchRestApi',
        name: 'Search接口',
        component: () => import('@/views/restapi/searchRestApi'),
        meta: { title: 'Search接口', icon: 'el-icon-search' }
      },
    ]
  },

  // {
  //   path: '/monitor',
  //   component: Layout,
  //   redirect: '/monitor/Eureka',
  //   name: '监控中心',
  //   meta: { title: '监控中心', icon: 'el-icon-s-platform' },
  //   children: [
  //     {
  //       path: 'OnlineAdmin',
  //       name: '在线用户',
  //       component: () => import('@/views/monitor/OnlineAdmin'),
  //       meta: { title: '在线用户', icon: 'el-icon-help' }
  //     },
  //     {
  //       path: 'Zipkin',
  //       name: 'Zipkin',
  //       component: () => import('@/views/monitor/Zipkin'),
  //       meta: { title: 'Zipkin', icon: 'el-icon-attract' }
  //     },
  //     {
  //       path: 'Druid',
  //       name: 'Druid',
  //       component: () => import('@/views/monitor/Druid'),
  //       meta: { title: 'Druid', icon: 'el-icon-coin' }
  //     },
  //     {
  //       path: 'RabbitMQ',
  //       name: 'RabbitMQ',
  //       component: () => import('@/views/monitor/RabbitMQ'),
  //       meta: { title: 'RabbitMQ', icon: 'el-icon-postcard' }
  //     },
  //   ]
  // },
  // {
  //   path: '/test',
  //   component: Layout,
  //   redirect: '/test/markdown',
  //   name: '测试页面',
  //   meta: { title: '测试页面', icon: 'el-icon-s-claim' },
  //   children: [
  //     {
  //       path: 'other',
  //       name: '其他',
  //       component: () => import('@/views/test/other'),
  //       meta: { title: '其他', icon: 'el-icon-folder-remove' }
  //     },
  //     {
  //       path: 'markdown',
  //       name: 'markdown',
  //       component: () => import('@/views/test/markdown'),
  //       meta: { title: 'markdown', icon: 'el-icon-notebook-1' }
  //     }
  //   ]
  // },

  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/table',
  //   name: 'Example',
  //   meta: { title: 'Example', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'table',
  //       name: 'Table',
  //       component: () => import('@/views/table/index'),
  //       meta: { title: 'Table', icon: 'table' }
  //     },
  //     {
  //       path: 'tree',
  //       name: 'Tree',
  //       component: () => import('@/views/tree/index'),
  //       meta: { title: 'Tree', icon: 'tree' }
  //     }
  //   ]
  // },

  // {
  //   path: '/form',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Form',
  //       component: () => import('@/views/form/index'),
  //       meta: { title: 'Form', icon: 'form' }
  //     }
  //   ]
  // },

  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       name: 'Menu2',
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
